package com.teemo.dp.singleton.demo8;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @author Teemo
 */
public class Demo {
    public static void main(String[] args) throws Exception{
        Washer washer = Washer.getInstance();
        Washer washer1 = Washer.getInstance();
        System.out.println(washer);
        System.out.println(washer1);

        // 序列化到内存流
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(washer);
        // 从内存流里面读取出来
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        Washer washer2 = (Washer) ois.readObject();

        washer2.wash();
        System.out.println(washer2);

    }
}
